home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / pmcstex.zip / PM_BINS.ZIP / CYKL.CMD < prev    next >
OS/2 REXX Batch file  |  1996-02-04  |  2KB  |  50 lines

  1. /* 
  2.   USAGE:   cykl  FILE COMMAND
  3.  
  4.   The following REXX program displays does forever (till Ctrl/C or kill):
  5.     - waits till FILE changes its size or time (i.e. till saving on the disk)
  6.     - then it runs COMMAND
  7.  
  8.   IMPORTANT: if COMMAND is .cmd file, then it must be COMMAND = call the_command
  9.  
  10.   Main purpose with example:
  11.   cykl seminar.tex cslatex seminar
  12.     => - wait till you save file  seminar.tex  from the editor, then run 
  13.          LaTeX on it (and dvipm updates the page, WONDERFUL TeX-ING!
  14.   Another example:
  15.   cykl hello.c call make
  16.  
  17.   Problems(?): CPU load measured by some apps is 100%. How to cheat them?
  18.   Try to use cykl!.cmd.
  19.  
  20.   Written by Petr Mikulik@sci.muni.cz, Brno, Dec 1995 / Jan 1996
  21.   Je to muj prvni REXX program, hura, a konecne jede!
  22. */
  23.  
  24. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  25. call SysLoadFuncs
  26.  
  27. parse arg WhichFile WhichCommand
  28. Call On Halt Name SignalHandler
  29.  
  30. /* convert slashes to backslahes if exist in the filename */
  31. /* do forever i=pos('/',WhichFile) if (i=0) then leave WhichFile=overlay('\',WhichFile,i) end */
  32. WhichFile = translate(WhichFile,'\','/') /* convert from unix format */
  33.  
  34. OldTime = ' '
  35. OldSize = ' '
  36. do forever
  37.   call SysFileTree WhichFile, 'file', 'FT'
  38.   NewTime = translate(word(file.1,1))
  39.   NewSize = translate(word(file.1,2))
  40.   if ((Compare(NewTime,OldTime)\=0) | (Compare(NewSize,OldSize)\=0)) then 
  41.     do 
  42.     call SysFileTree WhichFile, 'file', 'FT' /* cannot Old := New   */
  43.     OldTime = translate(word(file.1,1))      /* due to strange zero */
  44.     OldSize = translate(word(file.1,2))      /* filesize            */
  45.     WhichCommand
  46.     say "Cykl: Waiting for file change... (or Ctrl/C)"
  47.     end
  48. end
  49. SignalHandler:
  50.